# -*- coding: utf-8 -*-
# @Time    : 2022/5/25 21:09
# @Author  : zhangping
# @Email   : 2432115515@qq.com
# @File    : page_after_order.py
# @Software: PyCharm
"""后台订单管理页面"""
from time import sleep

from selenium.webdriver.common.by import By

from page.base_page import BasePage


class OrderPage(BasePage):
    # 订单管理定位器
    ele_order_locator = (By.CSS_SELECTOR, "#menu-ul > li.collapse.lis.ico_3")
    # 缺货登记定位器
    ele_stockout_locator = (By.LINK_TEXT, "缺货登记")
    #删除商品按钮定位器
    ele_delete_locator = (
    By.CSS_SELECTOR, "#listDiv > table:nth-child(1) > tbody > tr:nth-child(2) > td:nth-child(7) > a:nth-child(2) > img")
    # 查看商品定位器
    ele_stockout_goods_locator = (
    By.CSS_SELECTOR, "#listDiv > table:nth-child(1) > tbody > tr:nth-child(2) > td:nth-child(7) > a:nth-child(1) > img")
    # 输入处理备注 定位器
    ele_dispose_note_locator = (By.NAME, "dispose_note")
    # 点击我来处理定位器
    ele_do_goods_locator = (By.CSS_SELECTOR, "body > div.form-div > form > input.button")
    # 订单列表定位器
    ele_order_list_locator = (By.LINK_TEXT, "订单列表")
    # 查看订单定位器
    ele_order_check_locator = (By.XPATH, "/html/body/form/div[1]/table[1]/tbody/tr[3]/td[7]/a[1]")
    # 确认订单定位器
    ele_order_confirm_locator = (By.CSS_SELECTOR,
                                 "body > form > div:nth-child(4) > table > tbody > tr:nth-child(3) > td:nth-child(2) > input:nth-child(1)")
    # 配货定位器
    ele_order_distribution_locator = (By.NAME, "prepare")
    # 生成发货单定位器
    ele_order_dispatch_list_locator = (By.NAME, "ship")
    # 确认生成发货单定位器
    ele_order_confirm_dispatch_list_locator = (By.NAME, "delivery_confirmed")
    # 去发货定位器
    ele_order_to_shipment_locator = (By.CSS_SELECTOR,
                                     "body > form > div:nth-child(4) > table > tbody > tr:nth-child(3) > td:nth-child(2) > input:nth-child(1)")
    # 点击查看发货单列表中的订单
    ele_order_shipment_check_locator = (By.LINK_TEXT, "查看")
    # 点击发货定位器
    ele_order_shipment_btn_locator = (By.NAME, "delivery_confirmed")
    # 退货定位器
    ele_order_return_btn_locator = (By.NAME, "return")
    # 备注定位器
    ele_order_return_remark_locator = (
    By.CSS_SELECTOR, "body > form > div > table > tbody > tr:nth-child(1) > td > textarea")
    # 点击退货确定定位器
    ele_order_return_sure_locator = (
    By.CSS_SELECTOR, "body > form > div > table > tbody > tr:nth-child(2) > td > div > input:nth-child(1)")


    def ele_order(self):
        """点击订单管理"""
        self.driver.find_element(*self.ele_order_locator).click()
    def ele_stockout(self):
        """点击缺货登记"""
        self.driver.find_element(*self.ele_stockout_locator).click()
    def ele_to_stockout(self):
        """聚合：直接到缺货登记"""
        self.ele_order()
        self.ele_stockout()
    def ele_time(self):
        """点击登记时间"""
        self.driver.find_element(By.LINK_TEXT, "登记时间").click()
    def ele_delete(self):
        self.driver.find_element(*self.ele_delete_locator).click()
    def ele_stockout_goods(self):
        """点击查看商品"""
        self.driver.find_element(*self.ele_stockout_goods_locator).click()
    def ele_dispose_note(self):
        """输入处理备注"""
        self.driver.find_element(*self.ele_dispose_note_locator).send_keys("已补")
    def ele_do_goods(self):
        """点击我来处理"""
        self.driver.find_element(*self.ele_do_goods_locator).click()
    def ele_order_list(self):
        """点击订单列表"""
        self.driver.find_element(*self.ele_order_list_locator).click()
    def ele_to_order_list(self):
        """聚合：直接到订单列表"""
        self.ele_order()
        self.ele_order_list()
    def ele_order_check(self):
        """查看订单"""
        self.driver.find_element(*self.ele_order_check_locator).click()
    def ele_order_confirm(self):
        """点击订单确认"""
        self.driver.find_element(*self.ele_order_confirm_locator).click()
    def ele_to_order_confirm(self):
        """聚合：确认订单"""
        self.ele_order_check()
        self.ele_order_confirm()
    def ele_order_distribution(self):
        """点击配货"""
        self.driver.find_element(*self.ele_order_distribution_locator).click()
    def ele_order_dispatch_list(self):
        """点击生成发货单"""
        self.driver.find_element(*self.ele_order_dispatch_list_locator).click()
    def ele_order_confirm_dispatch_list(self):
        """点击确认生成发货单"""
        self.driver.find_element(*self.ele_order_confirm_dispatch_list_locator).click()
    def ele_to_dispatch(self):
        """点击去发货"""
        js = "window.scroll(0,329)"
        self.driver.execute_script(js)
        self.driver.find_element(*self.ele_order_to_shipment_locator).click()
    def ele_order_shipment_check(self):
        """查看发货订单"""
        self.driver.find_element(*self.ele_order_shipment_check_locator).click()
    def ele_order_shipment(self):
        """点击发货"""
        self.driver.find_element(*self.ele_order_shipment_btn_locator).click()
    def ele_to_order_shipment(self):
        """聚合：从配货到发货"""
        self.ele_order_distribution()
        sleep(5)
        self.ele_order_dispatch_list()
        self.ele_order_confirm_dispatch_list()
        sleep(5)
        self.ele_to_dispatch()
        sleep(5)
        self.ele_order_shipment_check()
        sleep(5)
        self.ele_order_shipment()
        sleep(3)
    def ele_order_return(self):
        """点击退货"""
        self.driver.find_element(*self.ele_order_return_btn_locator).click()
    def ele_order_return_remark(self):
        """输入退货备注"""
        self.driver.find_element(*self.ele_order_return_remark_locator).send_keys("退货")
    def ele_order_return_sure(self):
        """点击确定退货"""
        self.driver.find_element(*self.ele_order_return_sure_locator).click()
    def ele_to_order_return_sure(self):
        """聚合：确定退货"""
        sleep(4)
        self.ele_order_return()
        sleep(4)
        self.ele_order_return_remark()
        sleep(4)
        self.ele_order_return_sure()




